﻿using Loki.UI;

namespace Loki.Engine
{
    /// <summary>
    /// Context Helper.
    /// </summary>
    public static class ContextHelper
    {
        /// <summary>
        /// Gets the data engine.
        /// </summary>
        public static IDataEngine DataEngine
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the UI engine.
        /// </summary>
        public static IUIEngine UIEngine
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the model engine.
        /// </summary>
        public static IModelEngine ModelEngine
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the templating engine.
        /// </summary>
        public static ITemplatingEngine TemplatingEngine
        {
            get;
            private set;
        }

        public static void DefineApplicationEngine(IApplicationEngine P_ApplicationEngine, ITemplatingEngine P_TemplatingEngine)
        {
            DataEngine = P_ApplicationEngine;
            UIEngine = P_ApplicationEngine;
            ModelEngine = P_ApplicationEngine;
            TemplatingEngine = P_TemplatingEngine;
        }

        /// <summary>
        /// Defines the data engine.
        /// </summary>
        /// <param name="P_Engine">The data engine.</param>
        public static void DefineDataEngine(IDataEngine P_Engine)
        {
            DataEngine = P_Engine;
        }

        /// <summary>
        /// Defines the data engine.
        /// </summary>
        /// <param name="P_Engine">The model engine.</param>
        public static void DefineModelEngine(IModelEngine P_Engine)
        {
            ModelEngine = P_Engine;
        }

        /// <summary>
        /// Defines the data engine.
        /// </summary>
        /// <param name="P_Engine">The ui engine.</param>
        public static void DefineUIEngine(IUIEngine P_Engine)
        {
            UIEngine = P_Engine;
        }

        /// <summary>
        /// Defines the data engine.
        /// </summary>
        /// <param name="P_Engine">The templating engine.</param>
        public static void DefineTemplatingEngine(ITemplatingEngine P_Engine)
        {
            TemplatingEngine = P_Engine;
        }

        /// <summary>
        /// Loads the UI definitions.
        /// </summary>
        /// <param name="P_UIDefinitions">The p_ UI definitions.</param>
        public static void LoadUI(params string[] P_UIDefinitions)
        {
            UIEngine.LoadUI(P_UIDefinitions);
        }

        /// <summary>
        /// Loads the templates definitions.
        /// </summary>
        /// <param name="P_TemplatesDefinitions">The templates definitions.</param>
        public static void LoadTemplates(params string[] P_TemplatesDefinitions)
        {
            TemplatingEngine.LoadTemplates(P_TemplatesDefinitions);
        }

        /// <summary>
        /// Loads the model definitions.
        /// </summary>
        /// <param name="P_ModelDefinitions">The model definitions.</param>
        public static void LoadModel(params string[] P_ModelDefinitions)
        {
            ModelEngine.LoadModel(P_ModelDefinitions);
        }

        /// <summary>
        /// Loads the data definitions.
        /// </summary>
        /// <param name="P_DataDefinitions">The data definitions.</param>
        public static void LoadData(params string[] P_DataDefinitions)
        {
            DataEngine.LoadData(P_DataDefinitions);
        }

        /// <summary>
        /// Gets the application model.
        /// </summary>
        /// <typeparam name="TApplicationModel">The type of the application model.</typeparam>
        public static TApplicationModel GetApplicationModel<TApplicationModel>()
        {
            return ModelEngine.GetApplicationModel<TApplicationModel>();
        }

        /// <summary>
        /// Gets the data model.
        /// </summary>
        /// <typeparam name="TDataModel">The type of the model type.</typeparam>
        public static TDataModel GetDataModel<TDataModel>()
        {
            return DataEngine.GetDataModel<TDataModel>();
        }

        /// <summary>
        /// Gets the specified viewmodel.
        /// </summary>
        /// <typeparam name="TViewModel">The type of the view model type.</typeparam>
        public static TViewModel GetViewModel<TViewModel>() where TViewModel : IViewModel
        {
            return UIEngine.GetViewModel<TViewModel>();
        }

        /// <summary>
        /// Gets the specified viewmodel.
        /// </summary>
        /// <typeparam name="TViewModel">The type of the view model.</typeparam>
        /// <param name="P_ModelID">The model ID.</param>
        public static TViewModel GetViewModel<TViewModel>(string P_ModelID) where TViewModel : IViewModel
        {
            return UIEngine.GetViewModel<TViewModel>(P_ModelID);
        }

        /// <summary>
        /// Gets the view template for the specified viewmodel.
        /// </summary>
        /// <typeparam name="TView">The type of the view.</typeparam>
        /// <param name="P_ViewModel">The view model.</param>
        public static TView GetView<TView>(IViewModel P_ViewModel) where TView : IView
        {
            return TemplatingEngine.GetView<TView>(P_ViewModel);
        }
    }
}
